{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Read img"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "113"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取图片\n",
    "\n",
    "img=cv2.imread(\"./images/lena.jpg\")\n",
    "\n",
    "cv2.imshow(\"Output\",img)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Read videos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 读取视频\n",
    "\n",
    "cap=cv2.VideoCapture(\"./videos/test_video.mp4\")\n",
    "\n",
    "while True:\n",
    "    success,img = cap.read()\n",
    "    cv2.imshow(\"Video\",img)\n",
    "    \n",
    "    # set delay / break the loop\n",
    "    if cv2.waitKey(1) & 0xff == ord('q'):\n",
    "        break"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Using webcam"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 使用摄像头\n",
    "\n",
    "cap=cv2.VideoCapture(0)\n",
    "cap.set(3,640)    # 参数 3 宽度\n",
    "cap.set(4,480)    # 参数 4 高度\n",
    "cap.set(10,100)   # 参数 10 亮度\n",
    "\n",
    "while True:\n",
    "    success,img = cap.read()\n",
    "    cv2.imshow(\"Video\",img)\n",
    "    \n",
    "    # 设置延迟\n",
    "    # 设置停止按钮\n",
    "    if cv2.waitKey(1) & 0xff == ord('q'):\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
